//-------热键 相关脚本-----------
//add by bulargy.j.bai 2007.8.27
//热键定位功能
ie4 = (document.all) ? true : false;   	
ns4 = (document.layers) ? true : false;
//keys为字母按键

//功能类按键 0代表没按，1代表按了
var ctrl = "0",alt ="0",shift = "0",ieKey="",okKey="" ;

function keyDown(e){//按键按下后的处理
	if (ns4){   	
		var nKey=e.which;   	
		document.keyform.keytext.value="键值是"+nKey;   	
	}   	
	if (ie4){   			
		//-------进行 转换名字--------
		ieKeyCode=event.keyCode;
		var keys1 = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
		var keys2 = ["space","pageUp","pageDown","end","home","toLeft","toUp","toRight","toBottom"];		
		
		if(ieKeyCode=='8'){ieKey="back"; }
		else if(ieKeyCode=='9'){ieKey="tab";}
		else if(ieKeyCode=='13'){ieKey="enter";}
		//else if(ieKeyCode=='16'){ieKey="shift";}
		//else if(ieKeyCode=='17'){ieKey="ctrl";}
		//else if(ieKeyCode=='18'){ieKey="alt";}
		else if(ieKeyCode=='27'){ieKey="esc";}
		else if(ieKeyCode>=32 && ieKeyCode<=44 ){
			ieKey = keys2[ieKeyCode-32];
		}
		else if(ieKeyCode=='45'){ieKey="insert";}
		else if(ieKeyCode=='46'){ieKey="del";}
		else  if(ieKeyCode>=48 && ieKeyCode<=57){
			ieKey = ieKeyCode-48;
		}
		else if(ieKeyCode>=65 && ieKeyCode<=90){
			ieKey = keys1[ieKeyCode-65];
		}
		else if(ieKeyCode=='91'){ieKey="win";}
		else if(ieKeyCode=='92'){ieKey="win";}
		else if(ieKeyCode=='93'){ieKey="pop";}
		else if(ieKeyCode>=96 && ieKeyCode<=105){
			ieKey = ieKeyCode-96;
		}		
		else if(ieKeyCode=='123'){ieKey="f12";}		
		else if(ieKeyCode=='186'){ieKey=";";}		
		else if(ieKeyCode=='189'){ieKey="=";}
		else if(ieKeyCode=='188'){ieKey=",";}
		else if(ieKeyCode=='189'){ieKey="-";}
		else if(ieKeyCode=='190'){ieKey=".";}
		else if(ieKeyCode=='191'){ieKey="/";}
		else if(ieKeyCode=='192'){ieKey="`";}		
		else if(ieKeyCode=='219'){ieKey="[";}
		else if(ieKeyCode=='220'){ieKey="\\";}
		else if(ieKeyCode=='221'){ieKey="]";}
		else if(ieKeyCode=='222'){ieKey="'";}
		//--------------------------
		
		if(ieKey==undefined){ieKey="";}
		if(event.ctrlKey){ctrl = "1";}else{ctrl = "0";}
		if(event.altKey){alt = "1";}else{alt = "0";}
		if(event.shiftKey){shift = "1";}else{shift = "0";}		
	} 
	showKey();	
}	


function keyUp(e){//按键松开时的处理   
		if(event.ctrlKey){ctrl = "1";}else{ctrl = "0";}	
		if(event.shiftKey){shift = "1";}else{shift = "0";}
		if(event.altKey){alt = "1";}else{alt = "0";}
		//alert("ctrl = "+ctrl+" alt = "+alt+" shift = "+shift+" ieKey = "+ieKey);		
		//showKey();
		checkKey();
}

function showKey(){
	//alert("ctrl = "+ctrl+" alt = "+alt+" shift = "+shift+" ieKey = "+ieKey);		
	var keyset = document.getElementById("keyset");
	var keysetValue = "";
	if(ctrl == "1"){
		keysetValue += "ctrl+";
	};
	if(shift == "1"){
		keysetValue += "shift+";
	};
	if(alt == "1"){
		keysetValue += "alt+";
	};
	if(ieKey != ""){
		keysetValue += ieKey;
	};
	keyset.value = keysetValue;
	okKey = keysetValue;
}

function checkKey(){
	var keyset = document.getElementById("keyset");

	if(ieKey == ""){
		keyset.value = "无";
		okKey="";
	}else{
		if(okKey.split("+").length > 1){
			keyset.value = okKey;
		}else{
			keyset.value = "无";
			ieKey = "";
		}	
	}
}
//-------热键 相关脚本  结束-----------